Thumb

What is Type conversion?

1/8/2020 12:08:00 AM

When we convert the data type of the value then we convert the data type by Explicit. This data type can’t convert Automatic we write some Conversion code. Then it converts the data type. Now Given bellow the code and explain the code.

using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Reflection;
using testForClass1;
using System.IO;
using System.Runtime.Serialization.Formatters.Binary;

namespace testFor
{
    public class Program
    {
        static void Main(string[] args)
        {
            //Value assgin
            string name = "Farhan Sakib";
            int Id= 12;
            char word = 'J';
            double cgpa = 3.5;
            float gpa = 4.5f;
            //type conversion
            int cgpaToInt =Convert.ToInt32(3.5);
            double floatToDouble =Convert.ToDouble(4.5f);
            string charToString =Convert.ToString(word);
            double intToDouble = Id;
            Array stringToArray = name.ToArray();
            Console.Read();
        }
    }
}

In this code first we assign some value of the variable then we convert the value by the help of Convert class.